<?php
$this->pageTitle = 'Pridať obrat';
?>
<div class="newForm">
	<h3>Pridať obrat</h3>
	<?php echo $this->Form->create('Transfer'); ?>
	<fieldset>
		<?php
			$selectedOffer = $this->request->data ? $this->request->data['Transfer']['fk_offer_id'] : 0;
			echo '<div class="input select required">
				<label for="TransferFkOfferId">Ponuka</label>
				<select id="TransferFkOfferId" name="data[Transfer][fk_offer_id]">';
			foreach ($offers as $key => $offer) {
				echo '<option commission="' . $offer['commission'] . '" value="' . $key . '"' . ($selectedOffer == $key ? ' selected="selected"' : '') . ' onclick="changeCommission(this.getAttribute(\'commission\'));">' . $offer['title'] . '</option>';
			}

			echo '</select>
				</div>';
		
			echo $this->Form->input('fk_demand_id', array('label' => 'Dopyt', 'options' => $demands));
			echo $this->Form->input('commission', array('label' => 'Provízia'));
			echo '<div class="checkbox"><label for="TransferReferenced">Referenčný obchod</label>';
			echo $this->Form->checkbox('referenced');
			echo '</div>';
			echo $this->Form->hidden('calculated_shares');

			if (isset($commissions[1]) && is_array($commissions[1])) {
				echo '<br />';
				echo '<h4>Provízia pre makléra</h4>';
				foreach ($commissions[1] as $broker) {
					echo '<p>' . $broker['type'] . ' - ' . $broker['name'] . ' - ';
					echo $broker['percentage'] . ' % - ' . number_format($broker['value'], 2, ',', ' ') . ' &euro;</p>';
				}
			}

			if (isset($commissions[2]) && is_array($commissions[2]))  {
				echo '<br />';
				echo '<h4>Provízia za ponuku:</h4>';
				foreach ($commissions[2] as $offerCommissioner) {
					echo '<p>' . $offerCommissioner['type'] . ' - ' . $offerCommissioner['name'] . ' - ';
					echo $offerCommissioner['percentage'] . ' % - ' . number_format($offerCommissioner['value'], 2, ',', ' ') . ' &euro;</p>';
				}
			}

			if (isset($commissions[3]) && is_array($commissions[3]))  {
				echo '<br />';
				echo '<h4>Provízia za dopyt:</h4>';
				foreach ($commissions[3] as $demandCommissioner) {
					echo '<p>' . $demandCommissioner['type'] . ' - ' . $demandCommissioner['name'] . ' - ';
					echo $demandCommissioner['percentage'] . ' % - ' . number_format($demandCommissioner['value'], 2, ',', ' ') . ' &euro;</p>';
				}
			}

			if (isset($totalCommissioners) && $totalCommissioners) {
				echo '<br /><br />';
				echo '<h4>Provízia celkom:</h4>';
				foreach ($totalCommissioners as $commissioner) {
					echo '<p>' . $commissioner['type'] . ' - ' . $commissioner['name'] . ' - ' .
						$commissioner['total_commission_percentage'] . ' % - ' . number_format($commissioner['total_commission_value'], 2, ',', ' ') . ' &euro;</p>';
				}
			}

		?>
		<div class="submit">
			<?php echo $this->Form->button('Vypočítať', array('name' => 'calculate', 'value' => 1, 'id' => 'count')); ?>
		</div>
	</fieldset>

	<?php
		echo $this->Form->end(__('Uložiť'));
	?>
</div>